import {
  CmOrderActionDetailParams,
  CmOrderActionDetailResult,
  CmOrderActionParams,
  CmOrderActionResult,
  CmTenantAppParams,
  CmTenantAppResult,
  ImcSyncLogItem,
  ImcSyncLogParams,
  ImcSyncLogRespItem,
} from './model/integratedModel';
import { integratedHttp } from '/@/utils/http/axios';

enum Api {
  GET_CM_ORDER_ACTIONS = '/v1/integrated/cmOrderActions',
  GET_CM_ORDER_ACTION_DETAIL = '/v1/integrated/cmOrderActionDetail',
  GET_CM_TENANT_APPS = '/v1/integrated/cmTenantApps',
  GET_IMC_SYNC_LOGS = '/v1/integrated/imcSyncLogs',
}

export const getCmOrderActions = (params: CmOrderActionParams) => {
  return integratedHttp.get<CmOrderActionResult>({ url: Api.GET_CM_ORDER_ACTIONS, params });
};

export const getCmOrderActionDetail = (params: CmOrderActionDetailParams) => {
  return integratedHttp.get<CmOrderActionDetailResult>({
    url: Api.GET_CM_ORDER_ACTION_DETAIL,
    params,
  });
};

export const getCmTenantApps = (params: CmTenantAppParams) => {
  return integratedHttp.get<CmTenantAppResult>({ url: Api.GET_CM_TENANT_APPS, params });
};

export const getImcSyncLogs = async (params: ImcSyncLogParams) => {
  const resultTmp = await integratedHttp.post<ImcSyncLogRespItem[]>({
    url: Api.GET_IMC_SYNC_LOGS,
    params,
  });

  const resultList: ImcSyncLogItem[] = [];

  for (let i = 0; i < resultTmp.length; i++) {
    resultList.push(resultTmp[i].labels);
  }

  return resultList;
};
